var dialog = dialog || {};

dialog.frame = function(name,text,bgImage,bgColor,activation,z_index){
	this.name = name;
	this.child = new Array;
	this.x = 0;
	this.y = 0;
	this.z = z_index == undefined ? 0 : z_index;
	
	this.textContent = text[0];
	this.textCoordinateX = text[1] ? text[1] : 0;
	this.textCoordinateY = text[2] ? text[2] : 0;
	this.textTypeface = text[3] ? text[3] : "Microsoft YaHei";
	this.textSize = text[4] ? text[4] : 10;
	this.textColor = text[5] ? text[5] : [0,0,0,1];
	this.limitWidth = text[6] ? text[6] : 99999999;
	
	this.bgImageTexture = bgImage[0];
	this.bgImageTextureAlpha = bgImage[1] != undefined ? bgImage[1] : 1;
	this.bgImageWidth = bgImage[2];
	this.bgImageHeight = bgImage[3];
	
	this.bgColor = bgColor[0];
	this.bgWidth = bgColor[1];
	this.bgHeight = bgColor[2];
	this.bgDirection = bgColor[3];
	
	this.activating = true;
	
	if(activation["activeDown"]){
		this.activeDown = activation["activeDown"];
		}
		else{
			this.activeDown = function(){};
			}
			
	if(activation["activeOver"]){
		this.activeOver = activation["activeOver"];
		}
		else{
			this.activeOver = function(){};
			}
			
	if(activation["activeUp"]){
		this.activeUp = activation["activeUp"];
		}
		else{
			this.activeUp = function(){};
			}
	if(activation["activeDrag"]){
		this.activeDrag = activation["activeDrag"];
		}
		else{
			this.activeDrag = function(){};
			}
	if(activation["activeLeave"]){
		this.activeLeave = activation["activeLeave"];
		}
		else{
			this.activeLeave = function(){};
			}
	
	if(activation["defultFunction"]){
		this.defultFunction = activation["defultFunction"];
		}
		else{
			this.defultFunction = function(){};
		}
			
	this.transform = cubePack.createObject("Transform");
	this.transform.parent = menuMass.transform;
	this.scaleTransform = cubePack.createObject("Transform");
	this.scaleTransform.parent = this.transform;
	
	this.transform.translate(0,0,this.z);
	//----------------------------------------------------------------------
	if(this.bgImageTexture){
		this.bgImageMoveTransform = cubePack.createObject("Transform");
		this.bgImageMoveTransform.parent = this.scaleTransform;
		
		this.bgImageTransform = cubePack.createObject("Transform");
		this.bgImageTransform.parent = this.bgImageMoveTransform;
		
		this.bgImageSampler = cubePack.createObject('Sampler');
		this.bgImageSampler.addressModeU = cubeO3d.Sampler.CLAMP;
		this.bgImageSampler.addressModeV = cubeO3d.Sampler.CLAMP;
		
		this.bgImageParamSampler = this.bgImageTransform.createParam('texSampler0',
														'ParamSampler');
		this.bgImageParamSampler.value = this.bgImageSampler;
		this.bgImageParamColorMult = this.bgImageTransform.createParam('colorMult',
														'ParamFloat4');
		
		this.bgImageParamColorMult.set(1, 1, 1, this.bgImageTextureAlpha);
		
		this.bgImageSampler.texture = this.bgImageTexture;
		this.bgImageTransform.addShape(shape[3]);	
		
			if(this.bgImageWidth && this.bgImageHeight){
				this.width = this.bgImageWidth;
				this.height = this.bgImageHeight;
				}
			else{
				this.width = this.bgImageTexture.width;
				this.height = this.bgImageTexture.height;
				}
		this.bgImageTransform.translate(this.width/2,this.height/2,0);
		this.bgImageTransform.scale(this.width,-this.height,1);
		
		//this.bgImageMoveTransform.translate(this.bgImageCoordinateX,this.bgImageCoordinateX,0);
		}
		else if(this.bgColor  && this.bgColor[0] != undefined){
			this.width = this.bgWidth;
			this.height = this.bgHeight;
			
			this.bgImageMoveTransform = cubePack.createObject("Transform");
			this.bgImageMoveTransform.parent = this.scaleTransform;
			
			this.bgImageTransform = cubePack.createObject("Transform");
			this.bgImageTransform.parent = this.bgImageMoveTransform;
			
			this.bgColorTexture = cubePack.createTexture2D(
														 this.width,
														 this.height,
														 o3djs.base.o3d.Texture.ARGB8,
														 1,
														 false);
			
			var linearPaint = cubePack.createObject('CanvasPaint');

			
			this.bgImageCanvas = cubePack.createObject("Canvas");
			this.bgImageCanvas.setSize(this.width,this.height);
			
			if(this.bgColor[1][0] != undefined){
				this.bgImageCanvas.clear([0,0,0,0]);
				var gradientShader = cubePack.createObject("CanvasLinearGradient");
				switch(this.bgDirection){
					case "leftToRight":
						gradientShader.startPoint = [-1, 0];
						gradientShader.endPoint = [this.width-1, 0];
						break;
					case "rightToLeft":
						gradientShader.startPoint = [this.width-1, 0];
						gradientShader.endPoint = [-1, 0];
						break;
					case "downToUp":
						gradientShader.startPoint = [0, this.height-1];
						gradientShader.endPoint = [0, -1];
						break;
					case "upToDown":
						gradientShader.startPoint = [0, 0];
						gradientShader.endPoint = [0, this.height];
						break;
					default :
						gradientShader.startPoint = [0, 0];
						gradientShader.endPoint = [this.width, 0];
						break;
					}
					gradientShader.colors = this.bgColor;
					gradientShader.positions = [];
					gradientShader.tileMode = cubeO3d.CanvasShader.REPEAT;
				linearPaint.shader = gradientShader;
				this.bgImageCanvas.drawRect(0,0,this.width,this.height, linearPaint);
				}
			else{
				this.bgImageCanvas.clear(this.bgColor);
				}
			this.bgColorTexture.drawImage(this.bgImageCanvas,0,this.height-1,this.width,-this.height,
									   0,0,0,this.width,this.height
									   );
			this.bgImageSampler = cubePack.createObject('Sampler');
			this.bgImageSampler.addressModeU = cubeO3d.Sampler.CLAMP;
			this.bgImageSampler.addressModeV = cubeO3d.Sampler.CLAMP;
			
			this.bgImageParamSampler = this.bgImageTransform.createParam('texSampler0',
															'ParamSampler');
			this.bgImageParamSampler.value = this.bgImageSampler;
			this.bgImageParamColorMult = this.bgImageTransform.createParam('colorMult',
															'ParamFloat4');
			this.bgImageParamColorMult.set(1, 1, 1, 1);
				
			this.bgImageSampler.texture = this.bgColorTexture;
			this.bgImageTransform.addShape(shape[3]);	
			
			this.bgImageTransform.translate(this.width/2,this.height/2,0);
			this.bgImageTransform.scale(this.width,-this.height,1);
			//this.bgImageMoveTransform.translate(this.bgImageCoordinateX,this.bgImageCoordinateX,0);
			}
			else if(this.bgColor == undefined){
				this.width = this.bgWidth;
				this.height = this.bgHeight;
				}
	//========================================================================
	if(this.textContent){
		this.textMoveTransform = cubePack.createObject("Transform");
		this.textMoveTransform.parent = this.scaleTransform;
		
		this.textTransform = cubePack.createObject("Transform");
		this.textTransform.parent = this.textMoveTransform;
		
		
		this.textPaint = cubePack.createObject("CanvasPaint");
		this.textPaint.color = this.textColor;
		this.textPaint.textSize = this.textSize;
		this.textPaint.textTypeface = this.textTypeface;
		var fontBox = this.textPaint.measureText(this.textContent);
		this.textWidth = fontBox[2]-fontBox[0];
		this.textHeight = fontBox[3]-fontBox[1];
		
			if(this.textWidth>this.limitWidth){
				//按合适的宽度拆分字符串，保存到splitText（一个数组）
				var writeInRows = true;
				var splitText = dialog.splitTextBy(this.textPaint,this.textContent,this.limitWidth);
				fontBox = this.textPaint.measureText(splitText[0]);
				this.textWidth = this.limitWidth;
				this.textHeight = (fontBox[3]-fontBox[1]+3)*splitText.length;
				}
		
		if (this.textHeight%2 != 0){this.textHeight = this.textHeight +1;}
		if (this.textWidth %2 != 0){this.textWidth = this.textWidth +1;}
		
		this.textTexture = cubePack.createTexture2D(
													 this.textWidth,
													 this.textHeight,
													 o3djs.base.o3d.Texture.ARGB8,
													 1,
													 false);
		this.textCanvas = cubePack.createObject("Canvas");
		this.textCanvas.setSize(this.textWidth,this.textHeight);
		this.textCanvas.clear([1,1,1,0]);
		this.textTexture.drawImage(this.textCanvas,0,this.textHeight-1,this.textWidth,-this.textHeight,
								   0,0,0,this.textWidth,this.textHeight
								   );
		//根据暂存开关writeInRows来进入分支
			if(writeInRows){
				for(var nRows=0;nRows < splitText.length;nRows++){
					this.textCanvas.drawText(splitText[nRows],
										 -fontBox[0],
										 (fontBox[3]-fontBox[1])*(nRows+1)-fontBox[3]+nRows*3,
										 this.textPaint);
					}
				}
			else{
				this.textCanvas.drawText(this.textContent,
									 -fontBox[0],
									 this.textHeight-fontBox[3],
									 this.textPaint);
				}
		
		this.textTexture.drawImage(this.textCanvas,0,this.textHeight-1,this.textWidth,-this.textHeight,
								   0,0,0,this.textWidth,this.textHeight
								   );
		this.textSampler = cubePack.createObject('Sampler');
		this.textSampler.addressModeU = cubeO3d.Sampler.CLAMP;
		this.textSampler.addressModeV = cubeO3d.Sampler.CLAMP;
		
		this.textParamSampler = this.textTransform.createParam('texSampler0',
														'ParamSampler');
		this.textParamSampler.value = this.textSampler;
		this.textParamColorMult = this.textTransform.createParam('colorMult',
														'ParamFloat4');
		
		this.textParamColorMult.set(1, 1, 1, 1);
		
		this.textSampler.texture = this.textTexture;
		this.textTransform.addShape(shape[3]);	
		
		this.textTransform.translate(this.textWidth/2,this.textHeight/2,0.001);
		this.textTransform.scale(this.textWidth,-this.textHeight,1);
		
		if (!this.width){
			this.width = this.textWidth;
		}
		if (!this.height){
			this.height = this.textHeight;
 			}
		
		if (this.textCoordinateX  == "left"){
			this.textMoveTransform.translate(3,0,0);
			}else if (this.textCoordinateX  == "center"){
				this.textMoveTransform.translate(Math.round((this.width - this.textWidth - 3)/2),0,0);
				}else if(this.textCoordinateX  == "right"){
					this.textMoveTransform.translate(this.width - this.textWidth,0,0);
					}else {
						this.textMoveTransform.translate(this.textCoordinateX,0,0);
						}
		if (this.textCoordinateY  == "top"){
			this.textMoveTransform.translate(0,3,0);
			}else if (this.textCoordinateY  == "middle"){
				this.textMoveTransform.translate(0,Math.round((this.height - this.textHeight)/2),0);
				}else if(this.textCoordinateY  == "bottom"){
					this.textMoveTransform.translate(0,this.height - this.textHeight - 3,0);
					}else{
						this.textMoveTransform.translate(0,this.textCoordinateY,0);
						}
		}
	}
	
dialog.splitTextBy = function(textPaint,text,width){
	var textString;
	var splitTextArray = [];
	var splitNum = 0;
	var subSplitNum;
	for(var n=0;splitNum < text.length;n++){
		textString = text.slice(splitNum);
		
		subSplitNum = dialog._splitTextNext(textPaint,textString,width);
		splitNum += subSplitNum;
		
		splitTextArray[n] = textString.slice(0,subSplitNum);
		}
	return splitTextArray;
	}
	
dialog._splitTextNext = function(textPaint,text,width){
	//返回对这个text中，最靠近width的字符的编号
	var textString = text;
	var splitString; 
	var fontBox;
	var textWidth = 0;
	for(var n=0;textWidth < width && (n-2) < text.length;n++){
		splitString = textString.slice(0,n)
		fontBox = textPaint.measureText(splitString);
		textWidth = fontBox[2]-fontBox[0];
		}
	n--;
	n--;
	return n;
	} 	

dialog.frame.prototype.changeBgImageTexture = function(Param){
	var texture = Param[0];
	
	this.bgImageTexture = texture;
	this.bgImageSampler.texture = this.bgImageTexture;
	}

dialog.frame.prototype.changeBgColor = function(Param){
	var colorRed = Param[0] == undefined?  this.bgColor[0] :Param[0];
	var colorBlue = Param[1] == undefined?this.bgColor[1]: Param[1] ;
	var colorGreen = Param[2] == undefined? this.bgColor[2]:Param[2];
	var colorAlpha = Param[3] == undefined ? this.bgColor[3]:Param[3];
	
	this.bgColor =[colorRed,colorBlue,colorGreen,colorAlpha]; 
	
/*	cubePack.removeObject(this.bgImageCanvas);//
	
	this.bgImageCanvas = cubePack.createObject("Canvas");
	this.bgImageCanvas.setSize(this.width,this.height);
*/	this.bgImageCanvas.clear(this.bgColor);
	this.bgColorTexture.drawImage(this.bgImageCanvas,0,this.height-1,this.width,-this.height,
							   0,0,0,this.width,this.height
							   );
	
	}

dialog.frame.prototype.changeScale = function(Param){
	this.scaleTransform.identity();
	this.scaleTransform.scale(Param[0],Param[0],1);
	}


dialog.frame.prototype.moveTo = function(Param){
	this.x = Param[0];
	this.y = Param[1];
	this.transform.identity();
	this.transform.translate(Param[0],Param[1],this.z);
	
	}

dialog.frame.prototype.changeFrameAlpha = function(Param){
	var alpha = Param[0];
	
	if(this.textTransform){
		this.textParamColorMult.set(1, 1, 1, alpha);
		}
	if(this.bgImageTransform){
		this.bgImageParamColorMult.set(1, 1, 1, alpha);
		}
	
	for(var n=0;n < this.child.length;n++){
		this.child[n].changeFrameAlpha([alpha])
		}
	}
	
dialog.frame.prototype.changeTextAlpha = function(Param){
	var alpha = Param[0];
	
	if(this.textTransform){
		this.textParamColorMult.set(1, 1, 1, alpha);
		}
	}
	
dialog.frame.prototype.changeImageAlpha = function(Param){
	var alpha = Param[0];
	
	if(this.bgImageTransform){   //bgImageTransform 为 undefined？  
		this.bgImageParamColorMult.set(1, 1, 1, alpha);
		}
	}

dialog.frame.prototype.changeText = function(Param){
	var newContent = Param[0];
	var newTypeface = Param[1];
	var newSize = Param[2];
	var newColor = Param[3];
	var newCoordinateX = Param[4];
	var newCoordinateY = Param[5];
	var limitWidth = Param[6];
	
		if(newContent){
			this.textContent = newContent; 
			}
		if(newTypeface){
			this.textTypeface = newTypeface; 
			}
		if(newSize){
			this.textSize = newSize; 
			}
		if(newColor){
			this.textColor = newColor; 
			}
		if(newCoordinateX){
			this.textCoordinateX = newCoordinateX;
			}
		if(newCoordinateY){
			this.textCoordinateY = newCoordinateY;
			}
		if(limitWidth){
			this.limitWidth = limitWidth;
			}
		
		this.textPaint.color = this.textColor;
		this.textPaint.textSize = this.textSize;
		this.textPaint.textTypeface = this.textTypeface;
		
		var fontBox = this.textPaint.measureText(this.textContent);
		this.textWidth = fontBox[2]-fontBox[0];
		this.textHeight = fontBox[3]-fontBox[1];
		
			if(this.textWidth>this.limitWidth){
				//按合适的宽度拆分字符串，保存到splitText（一个数组）
				var writeInRows = true;
				var splitText = dialog.splitTextBy(this.textPaint,this.textContent,this.limitWidth);
				fontBox = this.textPaint.measureText(splitText[0]);
				this.textWidth = this.limitWidth;
				this.textHeight = (fontBox[3]-fontBox[1]+3)*splitText.length;
				}
		
		//删除之前的贴图
		if (this.textHeight%2 != 0){this.textHeight = this.textHeight +1;}
		if (this.textWidth %2 != 0){this.textWidth = this.textWidth +1;}
		cubePack.removeObject(this.textTexture);
		this.textTexture = cubePack.createTexture2D(
													 this.textWidth,
													 this.textHeight,
													 o3djs.base.o3d.Texture.ARGB8,
													 1,
													 false);
		this.textCanvas.setSize(this.textWidth,this.textHeight);
		this.textCanvas.clear([1,1,1,0]);
		this.textTexture.drawImage(this.textCanvas,0,this.textHeight-1,this.textWidth,-this.textHeight,
								   0,0,0,this.textWidth,this.textHeight
								   );
		//根据暂存开关writeInRows来进入分支
			if(writeInRows){
				for(var nRows=0;nRows < splitText.length;nRows++){
					this.textCanvas.drawText(splitText[nRows],
										 -fontBox[0],
										 (fontBox[3]-fontBox[1])*(nRows+1)-fontBox[3]+nRows*3,
										 this.textPaint);
					}
				}
			else{
				this.textCanvas.drawText(this.textContent,
									 -fontBox[0],
									 this.textHeight-fontBox[3],
									 this.textPaint);
				}
		this.textTexture.drawImage(this.textCanvas,0,this.textHeight-1,this.textWidth,-this.textHeight,
								   0,0,0,this.textWidth,this.textHeight
								   );
		this.textSampler.texture = this.textTexture;
		this.textParamColorMult.set(1, 1, 1, 1);
		this.textTransform.identity();
		this.textTransform.translate(this.textWidth/2,this.textHeight/2,0.001);
		this.textTransform.scale(this.textWidth,-this.textHeight,1);
		this.textMoveTransform.identity();
		
		if (this.textCoordinateX  == "left"){
			this.textMoveTransform.translate(3,0,0);
			}else if (this.textCoordinateX  == "center"){
				this.textMoveTransform.translate(Math.round((this.width - this.textWidth - 3)/2),0,0);
				}else if(this.textCoordinateX  == "right"){
					this.textMoveTransform.translate(this.width - this.textWidth,0,0);
					}else {
						this.textMoveTransform.translate(this.textCoordinateX,0,0);
						}
		if (this.textCoordinateY  == "top"){
			this.textMoveTransform.translate(0,3,0);
			}else if (this.textCoordinateY  == "middle"){
				this.textMoveTransform.translate(0,Math.round((this.height - this.textHeight)/2),0);
				}else if(this.textCoordinateY  == "bottom"){
					this.textMoveTransform.translate(0,this.height - this.textHeight - 3,0);
					}else{
						this.textMoveTransform.translate(0,this.textCoordinateY,0);
						}
	}
		
dialog.frame.prototype.moveTextTo = function(Param){
	var newX = Param[0];
	var newY = Param[1];
	
	this.textCoordinateX = newX;
	this.textCoordinateY = newY;
	this.textMoveTransform.identity();
	this.textMoveTransform.translate(this.textCoordinateX,this.textCoordinateY,0.001);
	}
	
//每个子集的Z值比他的父级大1，最后子集的z等于父级的z+1+0.01*子集号数
dialog.frame.prototype.addFrame = function(Param){
	var newChild = Param[0];
	var childX = Param[1] == undefined ? 0 : Param[1];
	var childY = Param[2] == undefined ? 0 : Param[2];
	var z_index = Param[3] == undefined ? this.z+1+this.child.length/100 : Param[2];
	newChild.transform.parent = this.scaleTransform;
	newChild.parent = this;
	this.child.push(newChild);
	newChild.transform.identity();
	newChild.transform.translate(childX,childY,z_index);
	newChild.x = childX;
	newChild.y = childY;
	newChild.z = z_index;
	}
	
dialog.frame.prototype.subFromParent = function(){
	for(var n=0;n < this.parent.child.length;n++){
		if(this.parent.child[n]==this){
			var thisNum = n;
			}
		}
	this.parent.child.splice(thisNum,1);
	this.transform.parent = menuMass.transform;
	this.transform.identity();
	this.parent = null;
	this.x = 0;
	this.y = 0;
	this.z = 0;
	}

dialog.frame.prototype.allActiveLeave = function(Param){
	//自身执行ctiveLeave；并且全部的子集也执行。
	this.activeLeave();
	if(this.child[0]){
		for(var n=0;n < this.child.length;n++){
			this.child[n].allActiveLeave();
			}
		}
	}

dialog.frame.prototype.changeZ = function(Param){
	var newZ = Param[0];
	this.z = newZ;
	this.transform.identity();
	this.transform.translate(this.x,this.y,newZ);
	}
	
dialog.frame.prototype.checkMouseDown = function(Param){
	var downX = Param[0];
	var downY = Param[1];
	
		if(downX>this.x && 
		   downX-this.x < this.width &&
		   downY>this.y && 
		   downY-this.y < this.height){
				var childDownX = downX-this.x;
				var childDownY = downY-this.y;
				if (this.activating){
					this.activeDown([childDownX,childDownY]);
					frameActiveNow.dragFrame.push([this,childDownX,childDownY]);
					}
				for(var n=0;n < this.child.length;n++){
					this.child[n].checkMouseDown([childDownX,childDownY]);
					}
			} 
	}           
	
dialog.frame.prototype.checkMouseOver = function(Param){
	var downX = Param[0];
	var downY = Param[1];
	if(downX>this.x && 
	   downX-this.x < this.width &&
	   downY>this.y && 
	   downY-this.y < this.height){
			var childDownX = downX-this.x;
			var childDownY = downY-this.y;
			if (this.activating){
			this.activeOver([childDownX,childDownY]);
			}else {
			
				}
			for(var n=0;n < this.child.length;n++){
				this.child[n].checkMouseOver([childDownX,childDownY]);
				}
		}
		else{
			this.allActiveLeave();
			}
	}                

dialog.frame.prototype.checkMouseUp = function(Param){
	var downX = Param[0];
	var downY = Param[1];
	
	if(downX>this.x && 
	   downX-this.x < this.width &&
	   downY>this.y && 
	   downY-this.y < this.height){
			var childDownX = downX-this.x;
			var childDownY = downY-this.y;
			if(this.activating){
			this.activeUp([childDownX,childDownY]);
			}else{
				
				
				}
			for(var n=0;n < this.child.length;n++){
				this.child[n].checkMouseUp([childDownX,childDownY]);
				}
			}
	}                

dialog.frame.prototype.checkMouseDrag = function(Param){
			var upOne = this;
			for(var downX = Param[0],downY = Param[1];
				upOne;
				upOne = upOne.parent){
										downX = downX-upOne.x;
										downY = downY-upOne.y;
										}
			this.activeDrag([downX,downY,Param[2],Param[3]]);
	}       
	
//active[0]为函数名，active[1]为函数条件，为数组。
dialog.frame.prototype.activeChildByName = function(childName,active){
	
	for (var n=0;n < this.child.length;n++){
		if(this.child[n].child){
			this.child[n].activeChildByName(childName,active);
			}
		if (this.child[n].name == childName){
			switch (active[0]){
				case  "moveTo":
					this.child[n].moveTo(active[1]);
					break;
				case "changeBgImageTexture":
					this.child[n].changeBgImageTexture(active[1]);
					break;
				case "changeBgColor" :
					this.child[n].changeBgColor(active[1]);
					break;
				case "changeFrameAlpha" :
					this.child[n].changeFrameAlpha(active[1]);
					break;
				case "changeTextAlpha":
					this.child[n].changeTextAlpha(active[1]);
					break;
				case "changeImageAlpha":
					this.child[n].changeImageAlpha(active[1]);
					break;
				case "addFrame":
					this.child[n].addFrame(active[1]);
					break;
				case "changeText":
					this.child[n].changeText(active[1]);
					break;
				case "getActive":
					this.child[n].getActive();
					break;
				case "loseActive":
					this.child[n].loseActive();
					break;
				case "changeScale" :
					this.child[n].changeScale(active[1]);
					break;
			}
		}
	}
	}
 
//被鼠标拖动的函数

dialog.frame.prototype.dragByMouse = function(){
	this.x = eyeMoveDelta[2] - eyeMoveDelta[0] + this.x;
	this.y = eyeMoveDelta[3] - eyeMoveDelta[1] + this.y;
	this.moveTo([this.x,this.y]);
	}


dialog.frame.prototype.loseActive = function (){
 for(var n = 0;n < this.child.length;n++){
	 this.child[n].loseActive();
	 }
	 this.activating = false;
	}

dialog.frame.prototype.getActive = function(){
	for(var n = 0;n < this.child.length;n++){
		this.child[n].getActive();
		}
		this.activating = true;
	}
	
dialog.frame.prototype.warnEffect = function(){
	clearInterval(frameMoveTime);
	var tStep = 20;
	var step = 0;
	this.changeFrameAlpha([0.2]);
	this.changeScale([0.8]);
	var thisFrame = this;
	frameMoveTime = setInterval(function(){dialog._frameWarnEffect(thisFrame,tStep,step);step++;},10);
	}

dialog._frameWarnEffect = function(frame,tStep,step){
	frame.changeFrameAlpha([Math.sin(step/tStep*PI/2)*0.8 + 0.8]);
	frame.changeScale([Math.sin(step/tStep*PI/2)*0.2 + 0.8]);
	if (step>=tStep){
		clearInterval(frameMoveTime);
		frameMoveTime = null;
		}
	}

	
	
	